home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / pcw.zip / FILES.SAV < prev    next >
Text File  |  1991-12-10  |  7KB  |  242 lines

  1.  
  2. /* files.c
  3.    25nov91
  4.    cb
  5.    files functions
  6. */
  7.  
  8. /* === includes ======================================== */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <dos.h>
  12. #include <conio.h>
  13. #include <ctype.h>
  14.  
  15. #include "pcwproto.h"
  16. #include "menu.h"
  17.  
  18. #include "files.h"
  19.  
  20. /* === defines ========================================= */
  21. #define FALSE 0
  22. #define TRUE  1
  23. #define ESC 0x1B
  24. #define EVER ;;
  25.  
  26. /* === prototypes ====================================== */
  27. static  int cmd_d(void);   /* get_Directory cmd */
  28. static  int cmd_h(void);   /* go_Shell cmd */
  29. static  int cmd_l(void);   /* file_Load cmd */
  30. static  int cmd_n(void);   /* file_New cmd */
  31. static  int cmd_s(void);   /* file_Save cmd */
  32. static  int cmd_w(void);   /* file_Write cmd */
  33. static void wait_for_something(void); /* wait for key or mse */
  34.  
  35. /* === files_menu() ==================================== */
  36. int files_menu(void)   /* do files */
  37. {
  38.    int cmd, result;
  39.    int i = 0;
  40.    WNDPTR *menuwnd;
  41.  
  42.    static PMNUFLDS filesoptions[] =
  43.       {{ 'L', " Load        "},
  44.        { 'N', " New         "},
  45.        { 'S', " Save        "},
  46.        { 'W', " Write to ..."},
  47.        { 'D', " Directory   "},
  48.        { 'H', " sHell       "},
  49.        { 'Q', " Quit        "},
  50.        {  0 , NULL }};
  51.  
  52.    static PMNUTYPE filesmenu =
  53.       { NULL,                         /* initial window ptr    */
  54.          3, 2, 11, 17,                /* window boundaries     */
  55.         YELLOW, BLUE,                 /* window color          */
  56.         SINGLEALL, LIGHTGRAY, BLUE,   /* border type and color */
  57.         "",                           /* menu title            */
  58.         TOP, MIDDLE, BLUE, LIGHTGRAY, /* title loc and color   */
  59.         YELLOW, MAGENTA,              /* select bar color      */
  60.         0,                            /* initial bar position  */
  61.         filesoptions };               /* ptr to options array  */
  62.  
  63.    if (mpresent) hide_mouse();
  64.    menuwnd = makepmenu(&filesmenu); /* create pop-up menu */
  65.    if (mpresent) show_mouse();
  66.    while (i != 'Q' && i != ESC)
  67.    {
  68.       i = pmenuinput(&filesmenu);   /* get value from menu */
  69.       switch(i)
  70.       {
  71.          case 'L': cmd = LOAD; break;
  72.          case 'N': cmd = NEW; break;
  73.          case 'S': cmd = SAVE; break;
  74.          case 'W': cmd = WRITE; break;
  75.          case 'D': cmd = DIR; break;
  76.          case 'H': cmd = SHELL; break;
  77.       }
  78.       if(i == 'Q' || i == ESC) result = 0;
  79.       else result = file(cmd);
  80.    }
  81.    if(mpresent) hide_mouse();
  82.    menuwnd = wpop(menuwnd);
  83.    if(mpresent) show_mouse();
  84.  
  85.    return(result);
  86. }
  87. /* --- end files_menu() -------------------------------- */
  88.  
  89.  
  90. /* === file() ========================================== */
  91. int file(int cmd)   /* do file functions */
  92. {
  93.    int result;
  94.    switch(cmd)
  95.    {
  96.       case   LOAD: result = cmd_l(); break;
  97.       case    NEW: result = cmd_n(); break;
  98.       case   SAVE: result = cmd_s(); break;
  99.       case  WRITE: result = cmd_w(); break;
  100.       case    DIR: result = cmd_d(); break;
  101.       case  SHELL: result = cmd_h(); break;
  102.           default: result = 99;
  103.    }
  104.  
  105.    return(result);
  106. }
  107. /* --- end file() -------------------------------------- */
  108.  
  109.  
  110. /* === cmd_d() ========================================= */
  111. static int cmd_d(void)   /* do dos Directory cmd */
  112. {
  113.     WNDPTR *wnd;
  114.     int mxr, mxc;
  115.  
  116.     if(mpresent) hide_mouse();
  117.     chk_video_state(&mxr, &mxc);
  118.     bordercolor(YELLOW, BLUE);
  119.     wnd = wframe(1, 18, 25, 59, LIGHTGRAY, BLUE);
  120.     wtitle(wnd, BOTTOM, RITE, " CURRENT DIRECTORY ");
  121.     set_int29();
  122.  
  123.     system("dir /p");
  124.  
  125.     puts("====== nifty! any key to return ======");
  126.     reset_int29();
  127.     if (mpresent) show_mouse();
  128.     wait_for_something();
  129.     if (mpresent) hide_mouse();
  130.     wpop(wnd);
  131.     if(mpresent) show_mouse();
  132.     return(0);
  133. }
  134. /* --- end cmd_d() ------------------------------------- */
  135.  
  136.  
  137. /* === cmd_h() ========================================= */
  138. static int cmd_h(void)   /* do sHell cmd */
  139. {
  140.     if(mpresent) hide_mouse();
  141.     qputs(12,CENTER,WHITE,BLACK, "go_sHell()");
  142.     if(mpresent) show_mouse();
  143.  
  144.     wait_for_something();
  145.  
  146.     if(mpresent) hide_mouse();
  147.     qputs(12,CENTER,WHITE,BLACK, "          ");
  148.     if(mpresent) hide_mouse();
  149.  
  150.     return(0);
  151. }
  152. /* --- end cmd_h() ------------------------------------- */
  153.  
  154.  
  155. /* === cmd_l() ========================================= */
  156. static int cmd_l(void)   /* file_Load cmd */
  157. {
  158.     if(mpresent) hide_mouse();
  159.     qputs(12,CENTER,WHITE,BLACK, "file_Load()");
  160.     if(mpresent) show_mouse();
  161.  
  162.     wait_for_something();
  163.  
  164.     if(mpresent) hide_mouse();
  165.     qputs(12,CENTER,WHITE,BLACK, "           ");
  166.     if(mpresent) hide_mouse();
  167.  
  168.     return(0);
  169. }
  170. /* --- end cmd_l() ------------------------------------- */
  171.  
  172.  
  173. /* === cmd_n() ========================================= */
  174. static int cmd_n(void)   /* file_New cmd */
  175. {
  176.     if(mpresent) hide_mouse();
  177.     qputs(12,CENTER,WHITE,BLACK, "file_New()");
  178.     if(mpresent) show_mouse();
  179.  
  180.     wait_for_something();
  181.  
  182.     if(mpresent) hide_mouse();
  183.     qputs(12,CENTER,WHITE,BLACK, "          ");
  184.     if(mpresent) hide_mouse();
  185.  
  186.     return(0);
  187. }
  188. /* --- end cmd_n() ------------------------------------- */
  189.  
  190.  
  191. /* === cmd_s() ========================================= */
  192. static int cmd_s(void)   /* go_Shell cmd */
  193. {
  194.     if(mpresent) hide_mouse();
  195.     qputs(12,CENTER,WHITE,BLACK, "file_Save()");
  196.     if(mpresent) show_mouse();
  197.  
  198.     wait_for_something();
  199.  
  200.     if(mpresent) hide_mouse();
  201.     qputs(12,CENTER,WHITE,BLACK, "           ");
  202.     if(mpresent) hide_mouse();
  203.  
  204.     return(0);
  205. }
  206. /* --- end cmd_s() ------------------------------------- */
  207.  
  208.  
  209. /* === cmd_w() ========================================= */
  210. static int cmd_w(void)   /* file_Write cmd */
  211. {
  212.     if(mpresent) hide_mouse();
  213.     qputs(12,CENTER,WHITE,BLACK, "file_Write()");
  214.     if(mpresent) show_mouse();
  215.  
  216.     wait_for_something();
  217.  
  218.     if(mpresent) hide_mouse();
  219.     qputs(12,CENTER,WHITE,BLACK, "            ");
  220.     if(mpresent) hide_mouse();
  221.  
  222.     return(0);
  223. }
  224. /* --- end cmd_w() ------------------------------------- */
  225.  
  226. /* === wait_for_something() ============================ */
  227. static void wait_for_something(void) /* wait for key or mse */
  228. {
  229.     int row, col, bstatus, done;
  230.     for(done = 0; !done; )          /*wait for something */
  231.     {
  232.        if(keypressed()) { keybrd_flush(); done++; }
  233.        if(mpresent)
  234.        {
  235.           if(get_mpressed(RITEM)) done++;
  236.           if(get_mpressed(LEFTM)) done++;
  237.           get_mpos(&row, &col, &bstatus);
  238.        }
  239.     }
  240. }
  241. /* --- end wait_for_something() ------------------------ */
  242.